package org.fintan.make.configs;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@Configuration  
@EnableAutoConfiguration  
//@ConfigurationProperties(prefix = "spring.redis",)  
public class RedisConfig {
	//private static Logger logger = Logger.getLogger(RedisConfig.class);  
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Value("${spring.redis.host}")
    private String host;  
	
	@Value("${spring.redis.port}")
    private int port;  
	
	@Value("${spring.redis.pool.timeout}")
    private int timeout;  
	
    @Value("${spring.redis.pool.max-idle}")
    private int maxIdle;

    @Value("${spring.redis.pool.max-wait}")
    private long maxWaitMillis;
    @Value("${spring.redis.pool.max-active}")
    private int maxActive;
    @Value("${spring.redis.pool.min-idle}")
    private long minIdle;
//	@Value("${spring.redis.password}")
 //   private String password;  
 
    @Bean
    public JedisPool redisPoolFactory() {
        logger.info("JedisPool注入成功！！");
        logger.info("redis地址：" + host + ":" + port);
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(maxActive);
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
		//最大连接数, 应用自己评估，不要超过ApsaraDB for Redis每个实例最大的连接数
    //    jedisPoolConfig.setTestOnBorrow(false);
   //     jedisPoolConfig.setTestOnReturn(false);
        
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);

        return jedisPool;
    }
//    @Bean
//    public Jedis jedis () {
//    	Jedis Jedis =redisPoolFactory().getResource();
//    	return Jedis;
//    }
  
}
